﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.ComponentModel;

using NSCore;
using NSApplication;


namespace NSPresentation
{
    /// <summary>
    /// winRun.xaml 的交互逻辑
    /// </summary>
    public partial class winRun : Window
    {
        public winRun()
        {
            InitializeComponent();
        }


        private void BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //注意这里是可以输入参数的，我们要把计算对象作为参数传递进去

            NSMath math = new NSMath(this._backgroudnWorker);

            Project p = e.Argument as Project;
            math.Compute(p.NSData,p.NSResult);





        }

        private void BackgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
        {




            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message, "错误");

            }
            else {


                ProjectService.CurrentService.Project.NSResult.TestReadData();


                MessageBox.Show("完成");
            
            }

        }

        private void BackgroundWorker_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
        {

            //调试

            MessageBox.Show(e.ProgressPercentage.ToString ());


        }

        BackgroundWorker _backgroudnWorker;

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this._backgroudnWorker = this.FindResource("bwRun") as BackgroundWorker;


        }

        private void btnStart_Click(object sender, RoutedEventArgs e)
        {

            Project p = ProjectService.CurrentService.Project;


            if (!this._backgroudnWorker.IsBusy)
            {
                this._backgroudnWorker.RunWorkerAsync(p);
                
            }
        }
       


    }
}
